package com.user.service;

import com.user.dao.UserDao;
import com.user.domain.User;

public class UserServiceImpl implements UserService {

	private UserDao userDao;

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void createUser(User user) {
		userDao.addUser(user);

	}

	public User getUserById(Integer uId) {
		return userDao.getUserById(uId);
	}

	public Page loadAll(Page page, UserQryHelper helper) {
		
		if (helper == null) {
			page.setColName("userId");
			page.setType("asc");
		} else {
			page.setColName(helper.getSortHelper().getColName());
			if(helper.getSortHelper().getSortedType().equals("desc")){
				page.setType("desc");
			}else
				page.setType("asc");
		}
		
		if (helper.getUserNo() != null) {
			page.setUserNo(helper.getUserNo());
		}
		if (helper.getUserName() != null) {
			page.setUserName(helper.getUserName());
		}
		if (helper.getUserStatus() != null) {
			page.setUserStatus(helper.getUserStatus());
		}
		
		page.setTotalRecNum(new Long(userDao.getCountUsers(page)));
		page.setContent(userDao.loadAll(page));
		return page;
	}

	public void modifyUser(User user) {
		userDao.updateUser(user);

	}

	public void removeUser(User user) {
		userDao.deleteUser(user);

	}

}
